# -*- coding: utf-8 -*-
# @Time: 2021/9/26 15:11
# @Author: yh
# @Remark: 设备状态db层
from typing import Iterator

from mxsoftpy import DB
from mxsoftpy.exception import DBError


class VideoStateDB(DB):

    def __except_error(self,fuc, **query):
        try:
            res = fuc(**query)
        except DBError as e:
            if e.err_code == 288:
                return None
            else:
                raise DBError(e.err_code)
        return res

    def select(self, videos: Iterator):
        """
        查询视频状态
        :param videos: 要查询的所有视频code
        """
        record_data = list()  # 存放所有巡检记录

        self.table.open(file='MXSE', table='VideoInspectionRecord')
        for video_code in videos:
            res = self.__except_error(self.table.filter,video_code=video_code)

            if res:
                record_data.extend(res)

        record_data.sort(key=lambda x: x['_FIELD_AUTOID_'])
        return record_data

#

